package com.seari.custody.controller;

import com.google.common.base.Strings;
import com.seari.custody.bean.ProjectSearchDTO;
import com.seari.custody.pojo.MessageBean;
import com.seari.custody.service.ProjectService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

/**
 * @author lxv1
 */
@RestController
@RequestMapping("/projects")
public class ProjectController {
    @Autowired
    private ProjectService projectService;

    /**
     * 模糊搜索工程名
     *
     * @param key
     * @return
     */
    @GetMapping("/search")
    public MessageBean searchProjectName(String key) {
        if (Strings.isNullOrEmpty(key)) {
            return MessageBean.success("查询关键字不可为空","");
        }
        List<ProjectSearchDTO> projectSearchDTOS = projectService.qryLikeProjectName(key);


        return MessageBean.success("查询项目名称成功", projectSearchDTOS);
    }

    /**
     * 动态选卡项
     * @param projectId
     * @return
     */
    @GetMapping("/dynamicCard/{projectId}")
    public MessageBean getProjectService(@PathVariable String projectId) {
        Map<String, String> dynamicSelectCard = projectService.dynamicSelectCard(projectId);
        return MessageBean.success("查询动态菜单成功",dynamicSelectCard);
    }
}
